package com.pureland.demo.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pureland.demo.domain.entity.Goods;
import com.pureland.demo.domain.req.GoodsQueryDTO;
import com.pureland.demo.mapper.GoodsMapper;
import com.pureland.demo.service.IDemoService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @projectName: pureland_cloud
 * @className: com.pureland.demo.service.impl.DemoServiceImpl
 * @description:
 * @author: tong.li
 * @createTime: 2020/10/16 20:16
 * @version: v1.0
 * @copyright: 版权所有 李彤 © 2020
 */
@Service
public class DemoServiceImpl  extends ServiceImpl<GoodsMapper, Goods>  implements IDemoService {


    @Override
    public PageInfo getGoodsList(GoodsQueryDTO queryDTO) {
        if (queryDTO.isEnable()){
            PageHelper.startPage(queryDTO.getPage(), queryDTO.getPageSize());
        }
        List<Goods> list = this.list(
                Wrappers.<Goods>lambdaQuery()
                        .eq(Objects.nonNull(queryDTO.getId()),Goods::getId, queryDTO.getId())
                        .like(!StringUtils.isEmpty(queryDTO.getName()),Goods::getName, queryDTO.getName())
                        .eq(Objects.nonNull(queryDTO.getPrice()),Goods::getPrice, queryDTO.getPrice())
                        .eq(Objects.nonNull(queryDTO.getTotal()),Goods::getPrice, queryDTO.getTotal())
                        .orderByDesc(Goods::getCreatedTime)
        );
        PageInfo pageInfo = new PageInfo<>(list == null ? Collections.EMPTY_LIST : list);
        return pageInfo;
    }

}
